# 按照面向对象思想定义页面对象【PO】
import time
from selenium.webdriver.common.by import By
from base.page_base import BasePage


class LoginPage(BasePage):
    """登录页"""

    def __init__(self, driver):
        """
        初始化方法：设置实例属性
        :param driver: 浏览器驱动
        """
        super().__init__(driver)  # 重写父类方法【扩展】
        self.phone = (By.ID, "keywords")
        self.password = (By.ID, "password")
        self.submit = (By.ID, "login-btn")
        # 登录成功结果定位
        self.res_success = (By.CLASS_NAME,"a-link1")
        # 登录失败结果定位
        self.res_fail = (By.XPATH, '//*[@id="err"]/span')


    def login(self, phone, pwd):
        """
        登录方法
        :param phone: 手机号
        :param pwd:密码
        :return:无
        """
        # self.fd_element(self.phone).clear()
        # self.fd_element(self.phone).send_keys(phone)
        # self.fd_element(self.password).clear()
        # self.fd_element(self.password).send_keys(pwd)
        # self.fd_element(self.submit).click()
        # 封装后的
        self.base_input(self.phone, phone)
        self.base_input(self.password, pwd)
        self.base_click(self.submit)

    def get_success_result(self):
        """
        获取登录成功结果
        :return:文本信息
        """
        time.sleep(2)
        return self.fd_element(self.res_success).text


    def get_fail_result(self):
        """
        获取登录失败结果
        :return:文本信息
        """
        # time.sleep(2)
        return self.fd_element(self.res_fail).text
